package com.zxy.supplier_system.server.xinyuan.repository

import com.zxy.supplier_system.server.xinyuan.entity.XinyuanGoods
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
interface XinyuanGoodsRepository :
    JpaRepository<XinyuanGoods, Int>,
    JpaSpecificationExecutor<XinyuanGoods> {

    // 根据条形码查找商品
    fun findByBarcode(barcode: String): XinyuanGoods?

    @Query("from XinyuanGoods  where (barcode like concat('%',?1,'%') or model like concat('%',?1,'%') or category.name like concat('%',?1,'%') or brand.name like concat('%',?1,'%')) and category.isHomeAppliance = ?2")
    fun searchByKeywordAndIsHomeAppliance(keyword: String,isHomeAppliance: Boolean): List<XinyuanGoods>
}